<?php
//返回变量
function ReturnRepUserVar(){
	$var="tablename,userid,username,password,dopass,salt,saltnum,email,registertime,register,changeregisterurl,registerurl,utfdata,userfen,money,loginurl,quiturl";
	return $var;
}

//提示信息
function InstallShowMsg($msg){
	echo"<script>alert('".$msg."');history.go(-1);</script>";
	exit();
}

//更新接口文件
function SetUserCOMConfig($add){
	$filetext=ReadFiletext('data/user.php');
	if(empty($filetext))
	{
		InstallShowMsg('文件 /e/update/data/user.php 丢失,安装不成功.');
	}
	$vr=explode(",",ReturnRepUserVar());
	$count=count($vr);
	for($i=0;$i<$count;$i++)
	{
		$filetext=str_replace("[!@--".$vr[$i]."--@!]",$add[$vr[$i]],$filetext);
	}
	//写入配置文件
	$fp=@fopen("../class/user.php","w");
	if(!$fp)
	{
		InstallShowMsg(' /e/class/user.php 文件权限没有设为0777，安装不成功.');
	}
	@fputs($fp,$filetext);
	@fclose($fp);
	//运行接口安装文件
	if($add['doinstall']==1)
	{
		echo"正运行接口安装程序......<script>self.location.href='index.php?install=1&setup=alter';</script>";
		exit();
	}
	elseif($add['doinstall']==2)
	{
		echo"正运行接口升级程序......<script>self.location.href='index.php?install=1&setup=update';</script>";
		exit();
	}
	echo"<script>self.location.href='index.php?setup=success';</script>";
	exit();
}

//运行安装接口文件
function InstallUserCOM(){
	global $empire;
	@include("../class/user.php");
	$user_userfen="enewsuserfen";
	$user_money="enewsmoney";
	$sql=$empire->query1("alter table ".$user_tablename." 
	add ".$user_group." smallint NOT NULL default '0',
	add ".$user_rnd." char(30) NOT NULL default '',
	add ".$user_userfen." int NOT NULL default '0',
	add ".$user_money." float(11,2) NOT NULL default '0.00',
	add ".$user_userdate." int not null default '0',
	add ".$user_zgroup." smallint not null default '0',
	add ".$user_havemsg." tinyint(1) not null default '0',
	add ".$user_checked." tinyint(1) not null default '1';");
	if(!$sql)
	{
		echo"运行安装接口程序出现以下错误:<br><font color=red>".mysql_error()."</font><br><br><a href='index.php'>点击返回重新设置</a>";
		exit();
	}
	db_close();
	$empire=null;
	echo"<script>self.location.href='index.php?setup=success';</script>";
	exit();
}

//运行升级接口文件
function UpdateUserCOM(){
	global $empire;
	@include("../class/user.php");
	/*
	$sql=$empire->query1("alter table ".$user_tablename." 
	add ".$user_checked." tinyint(1) not null default '1';");
	if(!$sql)
	{
		echo"运行安装接口程序出现以下错误:<br><font color=red>".mysql_error()."</font><br><br><a href='index.php'>点击返回重新设置</a>";
		exit();
	}
	*/
	db_close();
	$empire=null;
	echo"<script>self.location.href='index.php?setup=success';</script>";
	exit();
}

//导入默认项
function LoadUserCOMInfo($p){
	if($p)
	{
		$p=str_replace('/','',$p);
		$p=str_replace('.','',$p);
		$p=str_replace('\\','',$p);
		$f='data/def/'.$p.'.php';
	}
	else
	{
		$f='../class/user.php';
	}
	return $f;
}
?>